package rmi;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;

import po.UserIdentity;

import vo.BLToViewResultMessage;
import vo.BookVO;
import vo.CatalogVO;
import vo.CustomerBasicInfoVO;
import vo.GiftVO;
import vo.GradeSetVO;
import vo.OrderVO;
import vo.SalePolicyVO;
import bl.controller.AccountController;
import vo.UserVO;
import bl.controller.BookManagementController;
import bl.controller.CatalogManagementController;
import bl.controller.GiftController;
import bl.controller.LoginController;
import bl.controller.OrderManagementController;
import bl.service.AccountBLService;
import bl.controller.UserManagementController;
import bl.service.BookManagementBLService;
import bl.service.CatalogManagementBLService;
import bl.service.GiftBLService;
import bl.service.LoginBLService;
import bl.service.OrderManagementBLService;
import bl.service.UserManagementBLService;
import exception.GiftNotFoundException;
import exception.MemberNotFoundException;
import exception.OrderNotExistException;
import exception.PointsNotInRangeException;
import exception.GiftAlreadyExistException;
import exception.UserDeletedException;
import exception.UserNotExistException;
import exception.UserNotFoundException;
import exception.WrongPasswordException;

public class StaffServiceRemoteImpl extends UnicastRemoteObject implements StaffServiceRemote {
	
	private static final long serialVersionUID = 4756733500419350495L;

	public StaffServiceRemoteImpl() throws RemoteException {
		super();
	}

	public ArrayList<GiftVO> getGiftList(){
		GiftBLService service=new GiftController();
		ArrayList<GiftVO>giftVO=service.getGiftList();
		return giftVO;
	}
	
	public ArrayList<CustomerBasicInfoVO>getMemberList(){
		GiftBLService service=new GiftController();
		ArrayList<CustomerBasicInfoVO>customer=service.getMemberList();
		return customer;
	}
	
	public BLToViewResultMessage addGift(GiftVO gift){
		GiftBLService service=new GiftController();
		BLToViewResultMessage message=service.addGift(gift);
		return message;
	}
	
	public BLToViewResultMessage present(int giftID, int memberID)throws 
	                                     MemberNotFoundException, GiftNotFoundException,
	                                     PointsNotInRangeException,GiftAlreadyExistException{
		GiftBLService service=new GiftController();
		BLToViewResultMessage message=service.present(giftID, memberID);
		return message;
	}
	
    public BLToViewResultMessage salePolicy(SalePolicyVO salePolicy){ 
    	GiftBLService service=new GiftController();
		BLToViewResultMessage message=service.salePolicy(salePolicy);
		return message;
    }
    
    public BLToViewResultMessage MassPromotion(int GiftID,GradeSetVO gradeSet)
    		throws GiftNotFoundException, GiftAlreadyExistException{
    	GiftBLService service=new GiftController();
		BLToViewResultMessage message=service.MassPromotion(GiftID, gradeSet);
		return message;
    }
    
	public ArrayList<OrderVO> viewMemberOrder(int memberID) 
			throws MemberNotFoundException,OrderNotExistException{
		OrderManagementBLService service=new OrderManagementController();
		ArrayList<OrderVO>order=service.viewMemberOrder(memberID);
		return order;
	}
	
	public OrderVO viewOrder(int orderID)
			throws OrderNotExistException{
		OrderManagementBLService service=new OrderManagementController();
		OrderVO order=service.viewOrder(orderID);
		return order;
	}
	
	public BLToViewResultMessage changeOrderState(int orderID)
			throws OrderNotExistException{
		OrderManagementBLService service=new OrderManagementController();
		BLToViewResultMessage message=service.changeOrderState(orderID);
		return message;
	}

	@Override
	public ArrayList<CatalogVO> getCatalogList() throws RemoteException {
		CatalogManagementBLService catalog=new CatalogManagementController();
		ArrayList<CatalogVO>list=catalog.getCatalogList();
		return list;
	}

	@Override
	public BLToViewResultMessage addCatalog(String catalogName)
			throws RemoteException {
		CatalogManagementBLService catalog=new CatalogManagementController();
		BLToViewResultMessage message=catalog.addCatalog(catalogName);
		return message;
	}

	@Override
	public BLToViewResultMessage deleteCatalog(int catalogID)
			throws RemoteException {
		CatalogManagementBLService catalog=new CatalogManagementController();
		BLToViewResultMessage message=catalog.deleteCatalog(catalogID);
		return message;
	}

	@Override
	public BLToViewResultMessage modifyCatalog(int catalogID, String catalogName)
			throws RemoteException {
		CatalogManagementBLService catalog=new CatalogManagementController();
		BLToViewResultMessage message=catalog.modifyCatalog(catalogID, catalogName);
		return message;
	}

	@Override
	public ArrayList<BookVO> getBookList() throws RemoteException {
		BookManagementBLService service=new BookManagementController();
		ArrayList<BookVO>list=service.getBookList();
		return list;
	}

	@Override
	public BLToViewResultMessage addBook(BookVO book, int quantity)
			throws RemoteException {
		BookManagementBLService service=new BookManagementController();
		BLToViewResultMessage message=service.addBook(book, quantity);
		return message;
	}

	@Override
	public BLToViewResultMessage deleteBook(int bookID) throws RemoteException {
		BookManagementBLService service=new BookManagementController();
		BLToViewResultMessage message=service.deleteBook(bookID); 
		return message;
	}

	@Override
	public BLToViewResultMessage modifyBook(int bookID, BookVO book)
			throws RemoteException {
		BookManagementBLService service=new BookManagementController();
		BLToViewResultMessage message=service.modifyBook(bookID, book);
		return message;
	}

	public BLToViewResultMessage checkUsername(String username)throws RemoteException{
		AccountBLService service = new AccountController();
		BLToViewResultMessage message = service.checkUsername(username);
		return message;
	}
	
	@Override
	public int requireLogin(String username, String password,
			UserIdentity userIdentity) throws WrongPasswordException,
			UserDeletedException, UserNotExistException, RemoteException {
		LoginBLService service=new LoginController();
		int id=service.requireLogin(username, password, userIdentity);
		return id;
	}

	@Override
	public BLToViewResultMessage changePassword(int userID, String newPassword)
			throws UserNotFoundException, RemoteException {
		AccountBLService service = new AccountController();
		BLToViewResultMessage message = service.changePassword(userID, newPassword);
		return message;
	}

	@Override
	public CustomerBasicInfoVO requireMemberInfo(int memberID)
			throws MemberNotFoundException, RemoteException {
		AccountBLService service = new AccountController();
		CustomerBasicInfoVO customerBasicInfoVO = service.requireMemberInfo(memberID);
		return customerBasicInfoVO;
	}
	
	public ArrayList<UserVO> getUserList() throws RemoteException{
		UserManagementBLService service=new UserManagementController();
		ArrayList<UserVO> list=service.getUserList();
		return list;
	}

	public BLToViewResultMessage addUser(UserVO user) throws RemoteException{
		UserManagementBLService service=new UserManagementController();
		BLToViewResultMessage message=service.addUser(user);
		return message;
	}

	public BLToViewResultMessage deleteUser(int userID) throws RemoteException{
		UserManagementBLService service=new UserManagementController();
		BLToViewResultMessage message=service.deleteUser(userID);
		return message;
	}

	public BLToViewResultMessage modifyUser(int userID, UserVO user) throws RemoteException{
		UserManagementBLService service=new UserManagementController();
		BLToViewResultMessage message=service.modifyUser(userID, user);
		return message;
	}

}
